##=======================================================================## 
##=======================================================================## 
## Title:   Treating a Friend to Voter Registration in a Divided America ##
## Authors: M.V. (Trey) Hood III, Seth C. McKee,                         ##   
##          Enrijeta Shino, and Daniel A. Smith                          ##
## Journal: PlosOne                                                      ##
## Code update: 09/18/2025                                               ##
##=======================================================================## 
##=======================================================================## 

rm(list = ls())

library(readstata13)
library(foreign)
library(haven)
library(data.table)
library(descr)
library(texreg)
library(xtable)
library(tidyverse)
library(lubridate)
library(ggeffects)
library(margins)
library(haven)
library(nnet)
library(scales)
library(readxl)
library(forcats)

##=====================##
##=====================##
## Florida Survey Data ##
##=====================##
##=====================##

# upload dataset
fl_dta <- readRDS("/Users/Enrijeta/Dropbox/My Mac (MacBook-Pro.local)/Desktop/PLOSOne Data/fl_dta.rds")

##================##
# Recode variables #
##================##

# resident: 1 = yes; 0 = no; drop IDK
fl_dta$resident <- with(fl_dta, ifelse(Resident_of_State == 1, 1,
                                ifelse(Resident_of_State == 2, 0, NA)))

table(fl_dta$resident)

# attend local political meetings (such as school board or city council): 
# 1 = yes; 0 = no; drop IDK
fl_dta$pol_meeting <- with(fl_dta, ifelse(Pol_Part_1 == 1, 1,
                                   ifelse(Pol_Part_1 == 2, 0, NA)))

table(fl_dta$pol_meeting)

# put up a political sign (such as a lawn sign or bumper sticker): 
# 1 = yes; 0 = no; drop IDK
fl_dta$pol_sign <- with(fl_dta, ifelse(Pol_Part_2 == 1, 1,
                                ifelse(Pol_Part_2 == 2, 0, NA)))

table(fl_dta$pol_sign)

# work for a candidate or campaign:
# 1 = yes; 0 = no; drop IDK
fl_dta$pol_campaign <- with(fl_dta, ifelse(Pol_Part_3 == 1, 1,
                                    ifelse(Pol_Part_3 == 2, 0, NA)))

table(fl_dta$pol_campaign)

# attend a political protest, march or demonstration: 
# 1 = yes; 0 = no; drop IDK
fl_dta$pol_protest <- with(fl_dta, ifelse(Pol_Part_4 == 1, 1,
                                   ifelse(Pol_Part_4 == 2, 0, NA)))

table(fl_dta$pol_protest)

# contact a public official:
# 1 = yes; 0 = no; drop IDK
fl_dta$pol_official <- with(fl_dta, ifelse(Pol_Part_5 == 1, 1,
                                    ifelse(Pol_Part_5 == 2, 0, NA)))

table(fl_dta$pol_official)

# donate money to a candidate, campaign, or political organization:
# 1 = yes; 0 = no; drop IDK
fl_dta$pol_donate <- with(fl_dta, ifelse(Pol_Part_6 == 1, 1,
                                  ifelse(Pol_Part_6 == 2, 0, NA)))

table(fl_dta$pol_donate)

# political engagement scale
# crombach alpha for engagement scale items: alpha = 0.6; median r = 0.23 
fl_polengaged <- data.table(fl_dta)
fl_polengaged <- fl_polengaged[,.(pol_meeting, pol_sign, pol_campaign, 
                                  pol_protest, pol_official, pol_donate)]
psych::alpha(fl_polengaged[,c(1:6)])

# political engagement scale variable
fl_dta$pol_engagement <- fl_dta$pol_meeting + fl_dta$pol_sign + fl_dta$pol_campaign + 
  fl_dta$pol_protest + fl_dta$pol_official + fl_dta$pol_donate 
table(fl_dta$pol_engagement)

# recode political engagement scale: 0 --> 5 (combine 5 and 6 due to low cases)
fl_dta$pol_engagement5 <- with(fl_dta, ifelse(pol_engagement == 6, 5, pol_engagement))
table(fl_dta$pol_engagement5)

# usually vote in primary election: 1 = yes; 0 = no
fl_dta$vote_primary <- with(fl_dta, ifelse(Primary_Vote == 1, 1,
                                    ifelse(Primary_Vote == 2, 0, NA)))

table(fl_dta$vote_primary)

# voted in 2020 primary election: 1 = yes; 0 = no
fl_dta$vote_primary20 <- with(fl_dta, ifelse(Primary_2020 == 1, 1,
                                      ifelse(Primary_2020 == 2, 0, NA)))

table(fl_dta$vote_primary20)

# how important it is to vote in primary election: 1 (not important) --> 4 (very important)
fl_dta$vote_primary_imp <- with(fl_dta, ifelse(Importance_Primary == 4, 1,
                                        ifelse(Importance_Primary == 3, 2,
                                        ifelse(Importance_Primary == 2, 3,
                                        ifelse(Importance_Primary == 1, 4, NA)))))

table(fl_dta$vote_primary_imp)

# how important it is to vote in primary election: 1 = very important; 0 = not important
fl_dta$vote_primary_imp2 <- with(fl_dta, ifelse(vote_primary_imp > 2, 1, 0))

table(fl_dta$vote_primary_imp2)

# pid: 1 = Independent; 2 = Republican; 3 = Democrat; 4 = other; drop IDK
fl_dta$pid <- with(fl_dta, ifelse(Q45 == 1, 2, 
                           ifelse(Q45 == 2, 3,
                           ifelse(Q45 == 3, 1,
                           ifelse(Q45 == 4, 4, NA)))))

table(fl_dta$pid)

# party ID: 1 = NPA; 0 = other ( Republican; Democrat; other)
fl_dta$npa <- with(fl_dta, ifelse(pid == 1, 1, 0))
table(fl_dta$npa)

# party ID: 1 = Dem; 0 = Republican
fl_dta$dem <- with(fl_dta, ifelse(pid == 3, 1,
                           ifelse(pid == 2, 0, NA)))
table(fl_dta$dem)

# pid strength: 1 = strong republican ---> 7 = strong democrat
fl_dta$RStrength[fl_dta$RStrength == 3] <- NA
fl_dta$DStrength[fl_dta$DStrength == 3] <- NA

fl_dta$pid_strength <-  with(fl_dta, ifelse(RStrength == 1, 1,
                                     ifelse(RStrength == 2, 2, NA)))

fl_dta$pid_strength <-  with(fl_dta, ifelse(PLean == 1 & is.na(pid_strength), 3,
                                     ifelse(PLean == 2 & is.na(pid_strength), 5, 
                                     ifelse(PLean == 3 & is.na(pid_strength), 4, pid_strength))))

fl_dta$pid_strength <-  with(fl_dta, ifelse(DStrength == 2 & is.na(pid_strength), 6,
                                     ifelse(DStrength == 1 & is.na(pid_strength), 7, pid_strength)))

table(fl_dta$pid_strength)

# pid3: 1 = Independent; 2 = Republican, 3= Democrat
fl_dta$pid3 <- with(fl_dta, ifelse(pid_strength == 3 | pid_strength == 4 | 
                                   pid_strength == 5, 1,
                            ifelse(pid_strength == 6 | pid_strength == 7, 3, 2)))
table(fl_dta$pid3)

# pid strength: 1 = pure; 2 = leaning; 3 = weak; 4 = strong
fl_dta$pid_strength_cat4 <- with(fl_dta, ifelse(pid_strength == 4, 1,
                                         ifelse(pid_strength == 3 | pid_strength == 5, 2,
                                         ifelse(pid_strength == 2 | pid_strength == 6, 3, 4))))

table(fl_dta$pid_strength_cat4)

# pid strength: 1 = leaning; 0 = pure
fl_dta$pid_lean <- with(fl_dta, ifelse(pid_strength_cat4 == 2, 1,
                                ifelse(pid_strength_cat4 == 1, 0, NA)))

table(fl_dta$pid_lean)

# pid strength: 1 = strong; 0 = weak
fl_dta$pid_strong <- with(fl_dta, ifelse(pid_strength_cat4 == 4, 1,
                                  ifelse(pid_strength_cat4 == 3, 0, NA)))

table(fl_dta$pid_strong)

# political interest: 1 (hardly at all) --> 4 (most of the time)
fl_dta$Political_Interest[fl_dta$Political_Interest == 9] <- NA

fl_dta$pol_interest <- 5 - fl_dta$Political_Interest
table(fl_dta$pol_interest)

# nowadays, it is difficult for two people to talk about politics without getting into an argument:
# 1 = agree; 0 = disagree; drop IDK
fl_dta$talk_politics <- with(fl_dta, ifelse(Politics_1 == 1, 1,
                                     ifelse(Politics_1 == 2, 0, NA)))

table(fl_dta$talk_politics)

# nowadays, it is difficult to openly share your political views. 
# 1 = agree; 0 = disagree; drop IDK
fl_dta$shareviews_politics <- with(fl_dta, ifelse(Politics_2 == 1, 1,
                                           ifelse(Politics_2 == 2, 0, NA)))

table(fl_dta$shareviews_politics)

# I prefer to surround myself with politically like minded people
# 1 = agree; 0 = disagree; drop IDK
fl_dta$likeminded_politics <- with(fl_dta, ifelse(Politics_3 == 1, 1,
                                           ifelse(Politics_3 == 2, 0, NA)))

table(fl_dta$likeminded_politics)

# attention check: 1 = passed; 0 = failed (65 have failed)
fl_dta$attention_check <- ifelse(fl_dta$AttentionCheck == 1, 1, 0)
table(fl_dta$attention_check)

# Treatment: 
# 0 = control (FL)
# 1 = no info NC
# 2 = polarization cue FL
# 3 = polarization cue NC
# 4 = election law cue FL
# 5 = election law cue NC

fl_dta$treatment <- NA

fl_dta$treatment <- with(fl_dta, ifelse(Condition6 == 1| Condition6 == 2 |
                                        Condition6 == 3 | Condition6 == 4, 0, treatment))

fl_dta$treatment <- with(fl_dta, ifelse((Condition5 == 1 | Condition5 == 2 |
                                         Condition5 == 3 | Condition5 == 4) & is.na(treatment), 1, treatment))

fl_dta$treatment <- with(fl_dta, ifelse((Condition4 == 1| Condition4 == 2 |
                                         Condition4 == 3 | Condition4 == 4) & is.na(treatment), 2, treatment))

fl_dta$treatment <- with(fl_dta, ifelse((Condition3 == 1| Condition3 == 2 |
                                         Condition3 == 3 | Condition3 == 4) & is.na(treatment), 3, treatment))

fl_dta$treatment <- with(fl_dta, ifelse((Condition2 == 1| Condition2 == 2 |
                                         Condition2 == 3 | Condition2 == 4) & is.na(treatment), 4, treatment))

fl_dta$treatment <- with(fl_dta, ifelse((Condition1 == 1| Condition1 == 2 |
                                         Condition1 == 3 | Condition1 == 4) & is.na(treatment), 5, treatment))


table(fl_dta$treatment, useNA = "ifany")

# combine DV into one:
fl_dta$dv_reg <- coalesce(fl_dta$Condition1, fl_dta$Condition2, fl_dta$Condition3, 
                          fl_dta$Condition4, fl_dta$Condition5, fl_dta$Condition6)

table(fl_dta$dv_reg, useNA = "ifany")

# recode DV to register as: 1 = Independent; 2 = Republican; 3 = Democrat; 4 = other
fl_dta$dv_reg_n <- with(fl_dta, ifelse(dv_reg == 3, 1,
                                ifelse(dv_reg == 2, 2,
                                ifelse(dv_reg == 1, 3, 4))))
table(fl_dta$dv_reg_n)
table(fl_dta$dv_reg, fl_dta$treatment, useNA = "ifany")

# recode DV to register as: 1 = Independent; 0 = Republican/Democrat/other
fl_dta$dv_reg_all <- with(fl_dta, ifelse(dv_reg_n == 1, 1, 0))
table(fl_dta$dv_reg_all)

# recode DV to register as: 1 = Independent; 0 = Republican/Democrat
fl_dta$dv_reg_ind <- with(fl_dta, ifelse(dv_reg_n == 1, 1,
                                  ifelse(dv_reg_n == 4, NA, 0)))
table(fl_dta$dv_reg_ind)

# recode DV to register as: 0 = Independent; 1 = Republican/Democrat
fl_dta$dv_reg_partisan <- with(fl_dta, ifelse(dv_reg_n == 1, 0,
                                       ifelse(dv_reg_n == 4, NA, 1)))
table(fl_dta$dv_reg_partisan)

# manipulation check: 1 = passed; 0 = failed (531 failed)
fl_dta$manipulation_check <- ifelse(fl_dta$ManipulationCheck == 3, 1, 0)
table(fl_dta$manipulation_check)

# ideology: 1 = conservative --> 7 = liberal 
fl_dta$ideo7 <- 8 - fl_dta$Ideology
table(fl_dta$ideo7)

# ideology strength: 1= no ideologue; 2 = weak ideologist; 3 = ideologues; 4 = strong ideologues 
fl_dta$ideo_strength <- with(fl_dta, ifelse(ideo7 == 1 | ideo7 == 7, 4, 
                                     ifelse(ideo7 == 2 | ideo7 == 6, 3,
                                     ifelse(ideo7 == 3| ideo7 == 4, 2, 1))))
table(fl_dta$ideo_strength)

# party registration: 1 = Independent; 2 = Republican; 3 = Democrat; 4 = other; drop IDK
fl_dta$party_reg <- with(fl_dta, ifelse(PartyRegistration == 1, 3,
                                 ifelse(PartyRegistration == 2, 2,
                                 ifelse(PartyRegistration == 3, 1,
                                 ifelse(PartyRegistration == 4, 4, NA)))))
table(fl_dta$party_reg)

# party registration: 1 = Independent; 0 = (Republican/Democrat/other)
fl_dta$party_reg2 <- with(fl_dta, ifelse(party_reg==1, 1, 0))
table(fl_dta$party_reg2)

# did you move to Florida from another state? 1 = yes; 0 = no, drop idk
fl_dta$moveto_fl <- with(fl_dta, ifelse(Moved == 1, 1,
                                        ifelse(Moved == 2, 0, NA)))

table(fl_dta$moveto_fl)

# Age
fl_dta$age <- fl_dta$Age
table(fl_dta$age)

# gender: 1 = female; 0 = male; drop other (36 cases)
fl_dta$female <- with(fl_dta, ifelse(Gender == 1, 1,
                              ifelse(Gender == 2, 0, NA)))

table(fl_dta$female)

# race: 1 = white; 2 = black; 3 = Hispanic; 4 = other. There are 2 race variables(!!!!!)
fl_dta$race <- with(fl_dta, ifelse(RaceCES2022 > 3, 4, RaceCES2022))
table(fl_dta$race)
fl_dta$race <- factor(fl_dta$race)

# hispanic origin: 1 = yes; 0 = no
fl_dta$hispanic_origin <- ifelse(fl_dta$HispanicCES2022 == 2, 1, 0)
table(fl_dta$hispanic_origin)

# white non-hispanic
fl_dta$whitenh <- with(fl_dta, ifelse(race == 1 & hispanic_origin == 0, 1, 0))
table(fl_dta$whitenh)

# education: 1 = high school or less; 2 = some college; 3 = college; 4 = graduate 
fl_dta$education <- with(fl_dta, ifelse(Education < 3, 1,
                                 ifelse(Education == 3, 2,
                                 ifelse(Education == 4, 3, 4))))

table(fl_dta$education)

##============================##
##============================##
## North Carolina Survey Data ##
##============================##
##============================##

nc_dta <- readRDS("/Users/Enrijeta/Dropbox/My Mac (MacBook-Pro.local)/Desktop/PLOSOne Data/nc_dta.rds")

##================##
# Recode variables #
##================##

# resident: 1 = yes; 0 = no; drop IDK
nc_dta$resident <- with(nc_dta, ifelse(Resident_of_State == 1, 1,
                                ifelse(Resident_of_State == 2, 0, NA)))

table(nc_dta$resident)

# attend local political meetings (such as school board or city council): 
# 1 = yes; 0 = no; drop IDK
nc_dta$pol_meeting <- with(nc_dta, ifelse(Pol_Part_1 == 1, 1,
                                   ifelse(Pol_Part_1 == 2, 0, NA)))

table(nc_dta$pol_meeting)

# put up a political sign (such as a lawn sign or bumper sticker): 
# 1 = yes; 0 = no; drop IDK
nc_dta$pol_sign <- with(nc_dta, ifelse(Pol_Part_2 == 1, 1,
                                ifelse(Pol_Part_2 == 2, 0, NA)))

table(nc_dta$pol_sign)

# work for a candidate or campaign:
# 1 = yes; 0 = no; drop IDK
nc_dta$pol_campaign <- with(nc_dta, ifelse(Pol_Part_3 == 1, 1,
                                    ifelse(Pol_Part_3 == 2, 0, NA)))

table(nc_dta$pol_campaign)

# attend a political protest, march or demonstration: 
# 1 = yes; 0 = no; drop IDK
nc_dta$pol_protest <- with(nc_dta, ifelse(Pol_Part_4 == 1, 1,
                                   ifelse(Pol_Part_4 == 2, 0, NA)))

table(nc_dta$pol_protest)

# contact a public official:
# 1 = yes; 0 = no; drop IDK
nc_dta$pol_official <- with(nc_dta, ifelse(Pol_Part_5 == 1, 1,
                                    ifelse(Pol_Part_5 == 2, 0, NA)))

table(nc_dta$pol_official)

# donate money to a candidate, campaign, or political organization:
# 1 = yes; 0 = no; drop IDK
nc_dta$pol_donate <- with(nc_dta, ifelse(Pol_Part_6 == 1, 1,
                                  ifelse(Pol_Part_6 == 2, 0, NA)))

table(nc_dta$pol_donate)


# political engagement scale
# crombach alpha for engagement scale items: alpha = 0.62; median r = 0.23 
nc_polengaged <- data.table(nc_dta)
nc_polengaged <- nc_polengaged[,.(pol_meeting, pol_sign, pol_campaign, 
                                  pol_protest, pol_official, pol_donate)]
psych::alpha(nc_polengaged[,c(1:6)])

# political engagement scale variable
nc_dta$pol_engagement <- nc_dta$pol_meeting + nc_dta$pol_sign + nc_dta$pol_campaign + 
  nc_dta$pol_protest + nc_dta$pol_official + nc_dta$pol_donate 
table(nc_dta$pol_engagement)

# recode political engagement scale: 0 --> 5 (combine 5 and 6 due to low cases)
nc_dta$pol_engagement5 <- with(nc_dta, ifelse(pol_engagement == 6, 5, pol_engagement))
table(nc_dta$pol_engagement5)

# usually vote in primary election: 1 = yes; 0 = no
nc_dta$vote_primary <- with(nc_dta, ifelse(Primary_Vote == 1, 1,
                                    ifelse(Primary_Vote == 2, 0, NA)))

table(nc_dta$vote_primary)


# voted in 2020 primary election: 1 = yes; 0 = no
nc_dta$vote_primary20 <- with(nc_dta, ifelse(Primary_2020 == 1, 1,
                                      ifelse(Primary_2020 == 2, 0, NA)))

table(nc_dta$vote_primary20)

# how important it is to vote in primary election: 1 (not important) --> 4 (very important)
nc_dta$vote_primary_imp <- with(nc_dta, ifelse(Importance_Primary == 4, 1,
                                        ifelse(Importance_Primary == 3, 2,
                                        ifelse(Importance_Primary == 2, 3,
                                        ifelse(Importance_Primary == 1, 4, NA)))))

table(nc_dta$vote_primary_imp)

# how important it is to vote in primary election: 1 = very important; 0 = not important
nc_dta$vote_primary_imp2 <- with(nc_dta, ifelse(vote_primary_imp > 2, 1, 0))

table(nc_dta$vote_primary_imp2)


# pid: 1 = Independent; 2 = Republican; 3 = Democrat; 4 = other; drop IDK
nc_dta$pid <- with(nc_dta, ifelse(Q45 == 1, 2, 
                           ifelse(Q45 == 2, 3,
                           ifelse(Q45 == 3, 1,
                           ifelse(Q45 == 4, 4, NA)))))

table(nc_dta$pid)

# party ID: 1 = NPA; 0 = other ( Republican; Democrat; other)
nc_dta$npa <- with(nc_dta, ifelse(pid == 1, 1, 0))
table(nc_dta$npa)

# party ID: 1 = Dem; 0 = Republican
nc_dta$dem <- with(nc_dta, ifelse(pid == 3, 1,
                           ifelse(pid == 2, 0, NA)))
table(nc_dta$dem)

# pid strength: 1 = strong republican ---> 7 = strong democrat
nc_dta$RStrength[nc_dta$RStrength == 3] <- NA
nc_dta$DStrength[nc_dta$DStrength == 3] <- NA

nc_dta$pid_strength <-  with(nc_dta, ifelse(RStrength == 1, 1,
                                     ifelse(RStrength == 2, 2, NA)))

nc_dta$pid_strength <-  with(nc_dta, ifelse(PLean == 1 & is.na(pid_strength), 3,
                                     ifelse(PLean == 2 & is.na(pid_strength), 5, 
                                     ifelse(PLean == 3 & is.na(pid_strength), 4, pid_strength))))

nc_dta$pid_strength <-  with(nc_dta, ifelse(DStrength == 2 & is.na(pid_strength), 6,
                                     ifelse(DStrength == 1 & is.na(pid_strength), 7, pid_strength)))

table(nc_dta$pid_strength)

# pid3: 1 = Independent; 2 = Republican, 3= Democrat
nc_dta$pid3 <- with(nc_dta, ifelse(pid_strength == 3 | pid_strength == 4 | 
                                   pid_strength == 5, 1,
                            ifelse(pid_strength == 6 | pid_strength == 7, 3, 2)))

table(nc_dta$pid3)

# pid strength: 1 = pure; 2 = leaning; 3 = weak; 4 = strong
nc_dta$pid_strength_cat4 <- with(nc_dta, ifelse(pid_strength == 4, 1,
                                         ifelse(pid_strength == 3 | pid_strength == 5, 2,
                                         ifelse(pid_strength == 2 | pid_strength == 6, 3, 4))))

table(nc_dta$pid_strength_cat4)

# pid strength: 1 = leaning; 0 = pure
nc_dta$pid_lean <- with(nc_dta, ifelse(pid_strength_cat4 == 2, 1,
                                ifelse(pid_strength_cat4 == 1, 0, NA)))

table(nc_dta$pid_lean)

# pid strength: 1 = strong; 0 = weak
nc_dta$pid_strong <- with(nc_dta, ifelse(pid_strength_cat4 == 4, 1,
                                  ifelse(pid_strength_cat4 == 3, 0, NA)))

table(nc_dta$pid_strong)

# political interest: 1 (hardly at all) --> 4 (most of the time)
nc_dta$Political_Interest[nc_dta$Political_Interest == 9] <- NA

nc_dta$pol_interest <- 5 - nc_dta$Political_Interest
table(nc_dta$pol_interest)

# nowadays, it is difficult for two people to talk about politics without getting into an argument:
# 1 = agree; 0 = disagree; drop IDK
nc_dta$talk_politics <- with(nc_dta, ifelse(Politics_1 == 1, 1,
                                     ifelse(Politics_1 == 2, 0, NA)))

table(nc_dta$talk_politics)

# nowadays, it is difficult to openly share your political views. 
# 1 = agree; 0 = disagree; drop IDK
nc_dta$shareviews_politics <- with(nc_dta, ifelse(Politics_2 == 1, 1,
                                           ifelse(Politics_2 == 2, 0, NA)))

table(nc_dta$shareviews_politics)

# I prefer to surround myself with politically like minded people
# 1 = agree; 0 = disagree; drop IDK
nc_dta$likeminded_politics <- with(nc_dta, ifelse(Politics_3 == 1, 1,
                                           ifelse(Politics_3 == 2, 0, NA)))

table(nc_dta$likeminded_politics)

# attention check: 1 = passed; 0 = failed (10 failed)
nc_dta$attention_check <- ifelse(nc_dta$AttentionCheck == 1, 1, 0)
table(nc_dta$attention_check)

# Treatment: 
# 0 = control (NC)
# 1 = no info FL
# 2 = polarization cue FL
# 3 = polarization cue NC
# 4 = election law cue FL
# 5 = election law cue NC

nc_dta$treatment <- NA

nc_dta$treatment <- with(nc_dta, ifelse(Condition5 == 1 | Condition5 == 2 |
                                        Condition5 == 3 | Condition5 == 4, 0, treatment))

nc_dta$treatment <- with(nc_dta, ifelse((Condition6 == 1| Condition6 == 2 |
                                         Condition6 == 3 | Condition6 == 4) & is.na(treatment), 1, treatment))

nc_dta$treatment <- with(nc_dta, ifelse((Condition4 == 1| Condition4 == 2 |
                                         Condition4 == 3 | Condition4 == 4) & is.na(treatment), 2, treatment))

nc_dta$treatment <- with(nc_dta, ifelse((Condition3 == 1| Condition3 == 2 |
                                         Condition3 == 3 | Condition3 == 4) & is.na(treatment), 3, treatment))

nc_dta$treatment <- with(nc_dta, ifelse((Condition2 == 1| Condition2 == 2 |
                                         Condition2 == 3 | Condition2 == 4) & is.na(treatment), 4, treatment))

nc_dta$treatment <- with(nc_dta, ifelse((Condition1 == 1| Condition1 == 2 |
                                         Condition1 == 3 | Condition1 == 4) & is.na(treatment), 5, treatment))

table(nc_dta$treatment, useNA = "ifany")

# combine DV into one:
nc_dta$dv_reg <- coalesce(nc_dta$Condition1, nc_dta$Condition2, nc_dta$Condition3, 
                          nc_dta$Condition4, nc_dta$Condition5, nc_dta$Condition6)

table(nc_dta$dv_reg, useNA = "ifany")

# recode DV to register as: 1 = Independent; 2 = Republican; 3 = Democrat; 4 = other
nc_dta$dv_reg_n <- with(nc_dta, ifelse(dv_reg == 3, 1,
                                ifelse(dv_reg == 2, 2,
                                ifelse(dv_reg == 1, 3, 4))))
table(nc_dta$dv_reg_n)

table(nc_dta$dv_reg, nc_dta$treatment, useNA = "ifany")

# eecode DV to register as: 1 = Independent; 0 = Republican/Democrat/other
nc_dta$dv_reg_all <- with(nc_dta, ifelse(dv_reg_n == 1, 1, 0))
table(nc_dta$dv_reg_all)

# recode DV to register as: 1 = Independent; 0 = Republican/Democrat
nc_dta$dv_reg_ind <- with(nc_dta, ifelse(dv_reg_n == 1, 1,
                                  ifelse(dv_reg_n == 4, NA, 0)))
table(nc_dta$dv_reg_ind)

# recode DV to register as: 0 = Independent; 1 = Republican/Democrat
nc_dta$dv_reg_partisan <- with(nc_dta, ifelse(dv_reg_n == 1, 0,
                                       ifelse(dv_reg_n == 4, NA, 1)))
table(nc_dta$dv_reg_partisan)

# manipulation check: 1 = passed; 0 = failed (121 failed)
nc_dta$manipulation_check <- ifelse(nc_dta$ManipulationCheck == 2, 1, 0)
table(nc_dta$manipulation_check)

# ideology: 1 = conservative --> 7 = liberal 
nc_dta$ideo7 <- 8 - nc_dta$Ideology
table(nc_dta$ideo7)

# ideology strength: 1= no ideologue; 2 = weak ideologist; 3 = ideologues; 4 = strong ideologues 
nc_dta$ideo_strength <- with(nc_dta, ifelse(ideo7 == 1 | ideo7 == 7, 4, 
                                     ifelse(ideo7 == 2 | ideo7 == 6, 3,
                                     ifelse(ideo7 == 3| ideo7 == 4, 2, 1))))
table(nc_dta$ideo_strength)

# party registration: 1 = Independent; 2 = Republican; 3 = Democrat; 4 = other; drop IDK
nc_dta$party_reg <- with(nc_dta, ifelse(PartyRegistration == 1, 3,
                                 ifelse(PartyRegistration == 2, 2,
                                 ifelse(PartyRegistration == 3, 1,
                                 ifelse(PartyRegistration == 4, 4, NA)))))
table(nc_dta$party_reg)

# party registration: 1 = Independent; 0 = (Republican/Democrat/other)
nc_dta$party_reg2 <- with(nc_dta, ifelse(party_reg==1, 1, 0))
table(nc_dta$party_reg2)

# did you move to Florida from another state? 1 = yes; 0 = no, drop idk
nc_dta$moveto_nc <- with(nc_dta, ifelse(Moved == 1, 1,
                                        ifelse(Moved == 2, 0, NA)))

table(nc_dta$moveto_nc)

# age
nc_dta$age <- nc_dta$Age
table(nc_dta$age)

# gender: 1 = female; 0 = male; drop other (36 cases)
nc_dta$female <- with(nc_dta, ifelse(Gender == 1, 1,
                              ifelse(Gender == 2, 0, NA)))

table(nc_dta$female)

# race: 1 = white; 2 = black; 3 = Hispanic; 4 = other. There are 2 race variables(!!!!!)
nc_dta$race <- with(nc_dta, ifelse(RaceCES2022 > 3, 4, RaceCES2022))
table(nc_dta$race)
nc_dta$race <- factor(nc_dta$race)

# hispanic origin: 1 = yes; 0 = no
nc_dta$hispanic_origin <- ifelse(nc_dta$HispanicCES2022 == 2, 1, 0)
table(nc_dta$hispanic_origin)

# white non-hispanic
nc_dta$whitenh <- with(nc_dta, ifelse(race == 1 & hispanic_origin == 0, 1, 0))
table(nc_dta$whitenh)

# education: 1 = high school or less; 2 = some college; 3 = college; 4 = graduate 
nc_dta$education <- with(nc_dta, ifelse(Education < 3, 1,
                                 ifelse(Education == 3, 2,
                                 ifelse(Education == 4, 3, 4))))

table(nc_dta$education)

##==================##
# Florida: Figure 1 ##
##==================##

data2 <- read_excel("/Users/Enrijeta/Dropbox/Hood et al. Registered Indies/figures/figure2_fl.xlsx")

data2 %>% 
  mutate(Group = factor(Group)) %>% 
  mutate(Group = fct_relevel(Group, c("FL No cue (*C)", "NC No cue", "FL Polarization", "NC Polarization", 
                                      "FL Rule",  "NC Rule"))) %>%
  arrange(Group) %>% 
  ggplot(aes(x = Group, y = Mean)) +
  geom_col(width = 0.5, aes(fill = Group)) +  
  scale_fill_manual(values = c("FL No cue (*C)" = "darkgray", 
                               "NC No cue" = "darkgray",
                               "FL Polarization" = "forestgreen", 
                               "NC Polarization" = "forestgreen",
                               "FL Rule" = "darkorange", 
                               "NC Rule" = "darkorange")) +
  geom_errorbar(aes(ymin = Lower, ymax = Upper), width = 0.2) +  
  geom_text(aes(y = Mean, label = sprintf("%.2f", Mean)), vjust = -3) + 
  xlab("") +
  ylab("Register as NPA / Unaffiliated") +
  scale_y_continuous(breaks = seq(0, 1, by = 0.1), limits = c(0, 1)) +
  theme_bw() +
  theme(panel.background = element_rect(fill = "white"),
        legend.position = "none")

# save graph in overleaf
ggsave(filename = "/Users/Enrijeta/Dropbox/Apps/Overleaf/Independents_treatment/plots/fig1a.eps", dpi = 300, width = 6.5, height = 6)


##=========================##
# North Carolina: Figure 1 ##
##=========================##

data2_nc <- read_excel("/Users/Enrijeta/Dropbox/Hood et al. Registered Indies/figures/figure2_nc.xlsx")

data2_nc %>%
  mutate(Group = factor(Group)) %>%
  mutate(Group = fct_relevel(Group, c("FL No cue", "NC No cue (*C)", "FL Polarization", "NC Polarization", 
                                      "FL Rule",  "NC Rule"))) %>%
  arrange(Group) %>%
  ggplot(aes(x = Group, y = Mean)) +
  geom_col(width = 0.5, aes(fill = Group)) +  
  scale_fill_manual(values = c("FL No cue" = "darkgray", 
                               "NC No cue (*C)" = "darkgray",
                               "FL Polarization" = "forestgreen", 
                               "NC Polarization" = "forestgreen",
                               "FL Rule" = "darkorange", 
                               "NC Rule" = "darkorange")) +
  geom_errorbar(aes(ymin = Lower, ymax = Upper), width = 0.2) +
  geom_text(aes(label = round(Mean, 2), y = Upper), position = position_dodge(width = 0.5), vjust = -1) +  
  xlab("") +
  ylab("Register as NPA / Unaffiliated") +
  scale_y_continuous(breaks = seq(0, 1, by = 0.1), limits = c(0, 1)) +
  theme_bw() +
  theme(panel.background = element_rect(fill = "white"),
        legend.position = "none")

# save graph in overleaf
ggsave(filename = "/Users/Enrijeta/Dropbox/Apps/Overleaf/Independents_treatment/plots/fig1b.eps", dpi = 300, width = 6.5, height = 6)

##==================##
# Florida: Figure 2 ##
##==================##

data3 <- read_excel("/Users/Enrijeta/Dropbox/Hood et al. Registered Indies/figures/figure3_fl.xlsx")

data3 %>% 
  mutate(Group = factor(Group)) %>% 
  mutate(Group = fct_relevel(Group, c("FL No cue (*C)", "NC No cue", "FL Polarization", "NC Polarization", 
                                      "FL Rule",  "NC Rule"))) %>%
  arrange(Group) %>% 
  ggplot(aes(x = Group, y = Mean)) +
  geom_col(width = 0.5, aes(fill = Group)) +  
  scale_fill_manual(values = c("FL No cue (*C)" = "darkgray", 
                               "NC No cue" = "darkgray",
                               "FL Polarization" = "forestgreen", 
                               "NC Polarization" = "forestgreen",
                               "FL Rule" = "darkorange", 
                               "NC Rule" = "darkorange")) +
  geom_errorbar(aes(ymin = Lower, ymax = Upper), width = 0.2) +  
  geom_text(aes(y = Mean, label = sprintf("%.2f", Mean)), vjust = -3) + 
  xlab("") +
  ylab("Register as Partisan") +
  scale_y_continuous(breaks = seq(0, 1, by = 0.1), limits = c(0, 1)) +
  theme_bw() +
  theme(panel.background = element_rect(fill = "white"),
        legend.position = "none")

# save graph in overleaf
ggsave(filename = "/Users/Enrijeta/Dropbox/Apps/Overleaf/Independents_treatment/plots/fig2a.eps", dpi = 300, width = 6.5, height = 6)


##=========================##
# North Carolina: Figure 2 ##
##=========================##

data3_nc <- read_excel("/Users/Enrijeta/Dropbox/Hood et al. Registered Indies/figures/figure3_nc.xlsx")

data3_nc %>% 
  mutate(Group = factor(Group)) %>% 
  mutate(Group = fct_relevel(Group, c("FL No cue", "NC No cue (*C)", "FL Polarization", "NC Polarization", 
                                      "FL Rule",  "NC Rule"))) %>%
  arrange(Group) %>% 
  ggplot(aes(x = Group, y = Mean)) +
  geom_col(width = 0.5, aes(fill = Group)) +  
  scale_fill_manual(values = c("FL No cue" = "darkgrey", 
                               "NC No cue (*C)" = "darkgrey",
                               "FL Polarization" = "forestgreen", 
                               "NC Polarization" = "forestgreen",
                               "FL Rule" = "darkorange", 
                               "NC Rule" = "darkorange")) +
  geom_errorbar(aes(ymin = Lower, ymax = Upper), width = 0.2) +  
  geom_text(aes(y = Mean, label = round(Mean, 2)), vjust = -3, nudge_y = 0.05) + 
  xlab("") +
  ylab("Register as Partisan") +
  scale_y_continuous(breaks = seq(0, 1, by = 0.1), limits = c(0, 1)) +
  theme_bw() +
  theme(panel.background = element_rect(fill = "white"),
        legend.position = "none")

# save graph in overleaf
ggsave(filename = "/Users/Enrijeta/Dropbox/Apps/Overleaf/Independents_treatment/plots/fig2b.eps", dpi = 300, width = 6.5, height = 6)


##=====================================================##
## Appendix B Table B1: Florida: Balance of covariates ##
##=====================================================##

fl_dta <- data.frame(fl_dta)

crosstab(fl_dta$dv_reg_n, fl_dta$treat)

# DV
summary(fl_dta$dv_reg_n[fl_dta$treat==0])
sd(fl_dta$dv_reg_n[fl_dta$treat==0])

summary(fl_dta$dv_reg_n[fl_dta$treat==1])
sd(fl_dta$dv_reg_n[fl_dta$treat==1])

summary(fl_dta$dv_reg_n[fl_dta$treat==2])
sd(fl_dta$dv_reg_n[fl_dta$treat==2])

summary(fl_dta$dv_reg_n[fl_dta$treat==3])
sd(fl_dta$dv_reg_n[fl_dta$treat==3])

summary(fl_dta$dv_reg_n[fl_dta$treat==4])
sd(fl_dta$dv_reg_n[fl_dta$treat==4])

summary(fl_dta$dv_reg_n[fl_dta$treat==5])
sd(fl_dta$dv_reg_n[fl_dta$treat==5])


# Political engagement scale
crosstab(fl_dta$pol_engagement5, fl_dta$treat)

summary(fl_dta$pol_engagement5[fl_dta$treat==0])
sd(fl_dta$pol_engagement5[fl_dta$treat==0], na.rm = T)

summary(fl_dta$pol_engagement5[fl_dta$treat==1])
sd(fl_dta$pol_engagement5[fl_dta$treat==1], na.rm = T)

summary(fl_dta$pol_engagement5[fl_dta$treat==2])
sd(fl_dta$pol_engagement5[fl_dta$treat==2], na.rm = T)

summary(fl_dta$pol_engagement5[fl_dta$treat==3])
sd(fl_dta$pol_engagement5[fl_dta$treat==3], na.rm = T)

summary(fl_dta$pol_engagement5[fl_dta$treat==4])
sd(fl_dta$pol_engagement5[fl_dta$treat==4], na.rm = T)

summary(fl_dta$pol_engagement5[fl_dta$treat==5])
sd(fl_dta$pol_engagement5[fl_dta$treat==5], na.rm = T)


# Vote in primary 
crosstab(fl_dta$vote_primary, fl_dta$treat)

summary(fl_dta$vote_primary[fl_dta$treat==0])
sd(fl_dta$vote_primary[fl_dta$treat==0], na.rm = T)

summary(fl_dta$vote_primary[fl_dta$treat==1])
sd(fl_dta$vote_primary[fl_dta$treat==1], na.rm = T)

summary(fl_dta$vote_primary[fl_dta$treat==2])
sd(fl_dta$vote_primary[fl_dta$treat==2], na.rm = T)

summary(fl_dta$vote_primary[fl_dta$treat==3])
sd(fl_dta$vote_primary[fl_dta$treat==3], na.rm = T)

summary(fl_dta$vote_primary[fl_dta$treat==4])
sd(fl_dta$vote_primary[fl_dta$treat==4], na.rm = T)

summary(fl_dta$vote_primary[fl_dta$treat==5])
sd(fl_dta$vote_primary[fl_dta$treat==5], na.rm = T)


# Voted in the 2020 primary
crosstab(fl_dta$vote_primary20, fl_dta$treat)

summary(fl_dta$vote_primary20[fl_dta$treat==0])
sd(fl_dta$vote_primary20[fl_dta$treat==0], na.rm = T)

summary(fl_dta$vote_primary20[fl_dta$treat==1])
sd(fl_dta$vote_primary20[fl_dta$treat==1], na.rm = T)

summary(fl_dta$vote_primary20[fl_dta$treat==2])
sd(fl_dta$vote_primary20[fl_dta$treat==2], na.rm = T)

summary(fl_dta$vote_primary20[fl_dta$treat==3])
sd(fl_dta$vote_primary20[fl_dta$treat==3], na.rm = T)

summary(fl_dta$vote_primary20[fl_dta$treat==4])
sd(fl_dta$vote_primary20[fl_dta$treat==4], na.rm = T)

summary(fl_dta$vote_primary20[fl_dta$treat==5])
sd(fl_dta$vote_primary20[fl_dta$treat==5], na.rm = T)


# Important to vote in the primary election

crosstab(fl_dta$vote_primary_imp, fl_dta$treat)

summary(fl_dta$vote_primary_imp[fl_dta$treat==0])
sd(fl_dta$vote_primary_imp[fl_dta$treat==0], na.rm = T)

summary(fl_dta$vote_primary_imp[fl_dta$treat==1])
sd(fl_dta$vote_primary_imp[fl_dta$treat==1], na.rm = T)

summary(fl_dta$vote_primary_imp[fl_dta$treat==2])
sd(fl_dta$vote_primary_imp[fl_dta$treat==2], na.rm = T)

summary(fl_dta$vote_primary_imp[fl_dta$treat==3])
sd(fl_dta$vote_primary_imp[fl_dta$treat==3], na.rm = T)

summary(fl_dta$vote_primary_imp[fl_dta$treat==4])
sd(fl_dta$vote_primary_imp[fl_dta$treat==4], na.rm = T)

summary(fl_dta$vote_primary_imp[fl_dta$treat==5])
sd(fl_dta$vote_primary_imp[fl_dta$treat==5], na.rm = T)


# Party ID
crosstab(fl_dta$pid, fl_dta$treat)

summary(fl_dta$pid[fl_dta$treat==0])
sd(fl_dta$pid[fl_dta$treat==0], na.rm = T)

summary(fl_dta$pid[fl_dta$treat==1])
sd(fl_dta$pid[fl_dta$treat==1], na.rm = T)

summary(fl_dta$pid[fl_dta$treat==2])
sd(fl_dta$pid[fl_dta$treat==2], na.rm = T)

summary(fl_dta$pid[fl_dta$treat==3])
sd(fl_dta$pid[fl_dta$treat==3], na.rm = T)

summary(fl_dta$pid[fl_dta$treat==4])
sd(fl_dta$pid[fl_dta$treat==4], na.rm = T)

summary(fl_dta$pid[fl_dta$treat==5])
sd(fl_dta$pid[fl_dta$treat==5], na.rm = T)


# PID strength

crosstab(fl_dta$pid_strength, fl_dta$treat)

summary(fl_dta$pid_strength[fl_dta$treat==0])
sd(fl_dta$pid_strength[fl_dta$treat==0], na.rm = T)

summary(fl_dta$pid_strength[fl_dta$treat==1])
sd(fl_dta$pid_strength[fl_dta$treat==1], na.rm = T)

summary(fl_dta$pid_strength[fl_dta$treat==2])
sd(fl_dta$pid_strength[fl_dta$treat==2], na.rm = T)

summary(fl_dta$pid_strength[fl_dta$treat==3])
sd(fl_dta$pid_strength[fl_dta$treat==3], na.rm = T)

summary(fl_dta$pid_strength[fl_dta$treat==4])
sd(fl_dta$pid_strength[fl_dta$treat==4], na.rm = T)

summary(fl_dta$pid_strength[fl_dta$treat==5])
sd(fl_dta$pid_strength[fl_dta$treat==5], na.rm = T)


# Political interest
crosstab(fl_dta$pol_interest, fl_dta$treat)

summary(fl_dta$pol_interest[fl_dta$treat==0])
sd(fl_dta$pol_interest[fl_dta$treat==0], na.rm = T)

summary(fl_dta$pol_interest[fl_dta$treat==1])
sd(fl_dta$pol_interest[fl_dta$treat==1], na.rm = T)

summary(fl_dta$pol_interest[fl_dta$treat==2])
sd(fl_dta$pol_interest[fl_dta$treat==2], na.rm = T)

summary(fl_dta$pol_interest[fl_dta$treat==3])
sd(fl_dta$pol_interest[fl_dta$treat==3], na.rm = T)

summary(fl_dta$pol_interest[fl_dta$treat==4])
sd(fl_dta$pol_interest[fl_dta$treat==4], na.rm = T)

summary(fl_dta$pol_interest[fl_dta$treat==5])
sd(fl_dta$pol_interest[fl_dta$treat==5], na.rm = T)


# Talk politics
crosstab(fl_dta$talk_politics, fl_dta$treat)

summary(fl_dta$talk_politics[fl_dta$treat==0])
sd(fl_dta$talk_politics[fl_dta$treat==0], na.rm = T)

summary(fl_dta$talk_politics[fl_dta$treat==1])
sd(fl_dta$talk_politics[fl_dta$treat==1], na.rm = T)

summary(fl_dta$talk_politics[fl_dta$treat==2])
sd(fl_dta$talk_politics[fl_dta$treat==2], na.rm = T)

summary(fl_dta$talk_politics[fl_dta$treat==3])
sd(fl_dta$talk_politics[fl_dta$treat==3], na.rm = T)

summary(fl_dta$talk_politics[fl_dta$treat==4])
sd(fl_dta$talk_politics[fl_dta$treat==4], na.rm = T)

summary(fl_dta$talk_politics[fl_dta$treat==5])
sd(fl_dta$talk_politics[fl_dta$treat==5], na.rm = T)


# Share political views
crosstab(fl_dta$shareviews_politics, fl_dta$treat)

summary(fl_dta$shareviews_politics[fl_dta$treat==0])
sd(fl_dta$shareviews_politics[fl_dta$treat==0], na.rm = T)

summary(fl_dta$shareviews_politics[fl_dta$treat==1])
sd(fl_dta$shareviews_politics[fl_dta$treat==1], na.rm = T)

summary(fl_dta$shareviews_politics[fl_dta$treat==2])
sd(fl_dta$shareviews_politics[fl_dta$treat==2], na.rm = T)

summary(fl_dta$shareviews_politics[fl_dta$treat==3])
sd(fl_dta$shareviews_politics[fl_dta$treat==3], na.rm = T)

summary(fl_dta$shareviews_politics[fl_dta$treat==4])
sd(fl_dta$shareviews_politics[fl_dta$treat==4], na.rm = T)

summary(fl_dta$shareviews_politics[fl_dta$treat==5])
sd(fl_dta$shareviews_politics[fl_dta$treat==5], na.rm = T)


# Talk to like minded people
crosstab(fl_dta$likeminded_politics, fl_dta$treat)

summary(fl_dta$likeminded_politics[fl_dta$treat==0])
sd(fl_dta$likeminded_politics[fl_dta$treat==0], na.rm = T)

summary(fl_dta$likeminded_politics[fl_dta$treat==1])
sd(fl_dta$likeminded_politics[fl_dta$treat==1], na.rm = T)

summary(fl_dta$likeminded_politics[fl_dta$treat==2])
sd(fl_dta$likeminded_politics[fl_dta$treat==2], na.rm = T)

summary(fl_dta$likeminded_politics[fl_dta$treat==3])
sd(fl_dta$likeminded_politics[fl_dta$treat==3], na.rm = T)

summary(fl_dta$likeminded_politics[fl_dta$treat==4])
sd(fl_dta$likeminded_politics[fl_dta$treat==4], na.rm = T)

summary(fl_dta$likeminded_politics[fl_dta$treat==5])
sd(fl_dta$likeminded_politics[fl_dta$treat==5], na.rm = T)


# Ideology 

crosstab(fl_dta$ideo7, fl_dta$treat)

summary(fl_dta$ideo7[fl_dta$treat==0])
sd(fl_dta$ideo7[fl_dta$treat==0], na.rm = T)

summary(fl_dta$ideo7[fl_dta$treat==1])
sd(fl_dta$ideo7[fl_dta$treat==1], na.rm = T)

summary(fl_dta$ideo7[fl_dta$treat==2])
sd(fl_dta$ideo7[fl_dta$treat==2], na.rm = T)

summary(fl_dta$ideo7[fl_dta$treat==3])
sd(fl_dta$ideo7[fl_dta$treat==3], na.rm = T)

summary(fl_dta$ideo7[fl_dta$treat==4])
sd(fl_dta$ideo7[fl_dta$treat==4], na.rm = T)

summary(fl_dta$ideo7[fl_dta$treat==5])
sd(fl_dta$ideo7[fl_dta$treat==5], na.rm = T)


# Party registration
crosstab(fl_dta$party_reg, fl_dta$treat)

summary(fl_dta$party_reg[fl_dta$treat==0])
sd(fl_dta$party_reg[fl_dta$treat==0], na.rm = T)

summary(fl_dta$party_reg[fl_dta$treat==1])
sd(fl_dta$party_reg[fl_dta$treat==1], na.rm = T)

summary(fl_dta$party_reg[fl_dta$treat==2])
sd(fl_dta$party_reg[fl_dta$treat==2], na.rm = T)

summary(fl_dta$party_reg[fl_dta$treat==3])
sd(fl_dta$party_reg[fl_dta$treat==3], na.rm = T)

summary(fl_dta$party_reg[fl_dta$treat==4])
sd(fl_dta$party_reg[fl_dta$treat==4], na.rm = T)

summary(fl_dta$party_reg[fl_dta$treat==5])
sd(fl_dta$party_reg[fl_dta$treat==5], na.rm = T)


# Move to Florida
crosstab(fl_dta$moveto_fl, fl_dta$treat)

summary(fl_dta$moveto_fl[fl_dta$treat==0])
sd(fl_dta$moveto_fl[fl_dta$treat==0], na.rm = T)

summary(fl_dta$moveto_fl[fl_dta$treat==1])
sd(fl_dta$moveto_fl[fl_dta$treat==1], na.rm = T)

summary(fl_dta$moveto_fl[fl_dta$treat==2])
sd(fl_dta$moveto_fl[fl_dta$treat==2], na.rm = T)

summary(fl_dta$moveto_fl[fl_dta$treat==3])
sd(fl_dta$moveto_fl[fl_dta$treat==3], na.rm = T)

summary(fl_dta$moveto_fl[fl_dta$treat==4])
sd(fl_dta$moveto_fl[fl_dta$treat==4], na.rm = T)

summary(fl_dta$moveto_fl[fl_dta$treat==5])
sd(fl_dta$moveto_fl[fl_dta$treat==5], na.rm = T)



# Age
crosstab(fl_dta$age, fl_dta$treat)

summary(fl_dta$age[fl_dta$treat==0])
sd(fl_dta$age[fl_dta$treat==0], na.rm = T)

summary(fl_dta$age[fl_dta$treat==1])
sd(fl_dta$age[fl_dta$treat==1], na.rm = T)

summary(fl_dta$age[fl_dta$treat==2])
sd(fl_dta$age[fl_dta$treat==2], na.rm = T)

summary(fl_dta$age[fl_dta$treat==3])
sd(fl_dta$age[fl_dta$treat==3], na.rm = T)

summary(fl_dta$age[fl_dta$treat==4])
sd(fl_dta$age[fl_dta$treat==4], na.rm = T)

summary(fl_dta$age[fl_dta$treat==5])
sd(fl_dta$age[fl_dta$treat==5], na.rm = T)


# Female
crosstab(fl_dta$female, fl_dta$treat)

summary(fl_dta$female[fl_dta$treat==0])
sd(fl_dta$female[fl_dta$treat==0], na.rm = T)

summary(fl_dta$female[fl_dta$treat==1])
sd(fl_dta$female[fl_dta$treat==1], na.rm = T)

summary(fl_dta$female[fl_dta$treat==2])
sd(fl_dta$female[fl_dta$treat==2], na.rm = T)

summary(fl_dta$female[fl_dta$treat==3])
sd(fl_dta$female[fl_dta$treat==3], na.rm = T)

summary(fl_dta$female[fl_dta$treat==4])
sd(fl_dta$female[fl_dta$treat==4], na.rm = T)

summary(fl_dta$female[fl_dta$treat==5])
sd(fl_dta$female[fl_dta$treat==5], na.rm = T)


# Race

table(fl_dta$whitenh, fl_dta$treat)

summary(fl_dta$whitenh[fl_dta$treat==0])
sd(fl_dta$whitenh[fl_dta$treat==0], na.rm = T)

summary(fl_dta$whitenh[fl_dta$treat==1])
sd(fl_dta$whitenh[fl_dta$treat==1], na.rm = T)

summary(fl_dta$whitenh[fl_dta$treat==2])
sd(fl_dta$whitenh[fl_dta$treat==2], na.rm = T)

summary(fl_dta$whitenh[fl_dta$treat==3])
sd(fl_dta$whitenh[fl_dta$treat==3], na.rm = T)

summary(fl_dta$whitenh[fl_dta$treat==4])
sd(fl_dta$whitenh[fl_dta$treat==4], na.rm = T)

summary(fl_dta$whitenh[fl_dta$treat==5])
sd(fl_dta$whitenh[fl_dta$treat==5], na.rm = T)


# Hispanic origin
crosstab(fl_dta$hispanic_origin, fl_dta$treat)

summary(fl_dta$hispanic_origin[fl_dta$treat==0])
sd(fl_dta$hispanic_origin[fl_dta$treat==0], na.rm = T)

summary(fl_dta$hispanic_origin[fl_dta$treat==1])
sd(fl_dta$hispanic_origin[fl_dta$treat==1], na.rm = T)

summary(fl_dta$hispanic_origin[fl_dta$treat==2])
sd(fl_dta$hispanic_origin[fl_dta$treat==2], na.rm = T)

summary(fl_dta$hispanic_origin[fl_dta$treat==3])
sd(fl_dta$hispanic_origin[fl_dta$treat==3], na.rm = T)

summary(fl_dta$hispanic_origin[fl_dta$treat==4])
sd(fl_dta$hispanic_origin[fl_dta$treat==4], na.rm = T)

summary(fl_dta$hispanic_origin[fl_dta$treat==5])
sd(fl_dta$hispanic_origin[fl_dta$treat==5], na.rm = T)


# Education

crosstab(fl_dta$education, fl_dta$treat)

summary(fl_dta$education[fl_dta$treat==0])
sd(fl_dta$education[fl_dta$treat==0], na.rm = T)

summary(fl_dta$education[fl_dta$treat==1])
sd(fl_dta$education[fl_dta$treat==1], na.rm = T)

summary(fl_dta$education[fl_dta$treat==2])
sd(fl_dta$education[fl_dta$treat==2], na.rm = T)

summary(fl_dta$education[fl_dta$treat==3])
sd(fl_dta$education[fl_dta$treat==3], na.rm = T)

summary(fl_dta$education[fl_dta$treat==4])
sd(fl_dta$education[fl_dta$treat==4], na.rm = T)

summary(fl_dta$education[fl_dta$treat==5])
sd(fl_dta$education[fl_dta$treat==5], na.rm = T)



##============================================================##
## Appendix B Table B2: North Carolina: Balance of covariates ##
##============================================================##

nc_dta <- data.frame(nc_dta)

crosstab(nc_dta$dv_reg_n, nc_dta$treat)

# DV
summary(nc_dta$dv_reg_n[nc_dta$treat==0])
sd(nc_dta$dv_reg_n[nc_dta$treat==0])

summary(nc_dta$dv_reg_n[nc_dta$treat==1])
sd(nc_dta$dv_reg_n[nc_dta$treat==1])

summary(nc_dta$dv_reg_n[nc_dta$treat==2])
sd(nc_dta$dv_reg_n[nc_dta$treat==2])

summary(nc_dta$dv_reg_n[nc_dta$treat==3])
sd(nc_dta$dv_reg_n[nc_dta$treat==3])

summary(nc_dta$dv_reg_n[nc_dta$treat==4])
sd(nc_dta$dv_reg_n[nc_dta$treat==4])

summary(nc_dta$dv_reg_n[nc_dta$treat==5])
sd(nc_dta$dv_reg_n[nc_dta$treat==5])


# Political engagement scale
crosstab(nc_dta$pol_engagement5, nc_dta$treat)

summary(nc_dta$pol_engagement5[nc_dta$treat==0])
sd(nc_dta$pol_engagement5[nc_dta$treat==0], na.rm = T)

summary(nc_dta$pol_engagement5[nc_dta$treat==1])
sd(nc_dta$pol_engagement5[nc_dta$treat==1], na.rm = T)

summary(nc_dta$pol_engagement5[nc_dta$treat==2])
sd(nc_dta$pol_engagement5[nc_dta$treat==2], na.rm = T)

summary(nc_dta$pol_engagement5[nc_dta$treat==3])
sd(nc_dta$pol_engagement5[nc_dta$treat==3], na.rm = T)

summary(nc_dta$pol_engagement5[nc_dta$treat==4])
sd(nc_dta$pol_engagement5[nc_dta$treat==4], na.rm = T)

summary(nc_dta$pol_engagement5[nc_dta$treat==5])
sd(nc_dta$pol_engagement5[nc_dta$treat==5], na.rm = T)


# Vote in primary 
crosstab(nc_dta$vote_primary, nc_dta$treat)

summary(nc_dta$vote_primary[nc_dta$treat==0])
sd(nc_dta$vote_primary[nc_dta$treat==0], na.rm = T)

summary(nc_dta$vote_primary[nc_dta$treat==1])
sd(nc_dta$vote_primary[nc_dta$treat==1], na.rm = T)

summary(nc_dta$vote_primary[nc_dta$treat==2])
sd(nc_dta$vote_primary[nc_dta$treat==2], na.rm = T)

summary(nc_dta$vote_primary[nc_dta$treat==3])
sd(nc_dta$vote_primary[nc_dta$treat==3], na.rm = T)

summary(nc_dta$vote_primary[nc_dta$treat==4])
sd(nc_dta$vote_primary[nc_dta$treat==4], na.rm = T)

summary(nc_dta$vote_primary[nc_dta$treat==5])
sd(nc_dta$vote_primary[nc_dta$treat==5], na.rm = T)


# Voted in the 2020 primary
crosstab(nc_dta$vote_primary20, nc_dta$treat)

summary(nc_dta$vote_primary20[nc_dta$treat==0])
sd(nc_dta$vote_primary20[nc_dta$treat==0], na.rm = T)

summary(nc_dta$vote_primary20[nc_dta$treat==1])
sd(nc_dta$vote_primary20[nc_dta$treat==1], na.rm = T)

summary(nc_dta$vote_primary20[nc_dta$treat==2])
sd(nc_dta$vote_primary20[nc_dta$treat==2], na.rm = T)

summary(nc_dta$vote_primary20[nc_dta$treat==3])
sd(nc_dta$vote_primary20[nc_dta$treat==3], na.rm = T)

summary(nc_dta$vote_primary20[nc_dta$treat==4])
sd(nc_dta$vote_primary20[nc_dta$treat==4], na.rm = T)

summary(nc_dta$vote_primary20[nc_dta$treat==5])
sd(nc_dta$vote_primary20[nc_dta$treat==5], na.rm = T)


# Important to vote in the primary election

crosstab(nc_dta$vote_primary_imp, nc_dta$treat)

summary(nc_dta$vote_primary_imp[nc_dta$treat==0])
sd(nc_dta$vote_primary_imp[nc_dta$treat==0], na.rm = T)

summary(nc_dta$vote_primary_imp[nc_dta$treat==1])
sd(nc_dta$vote_primary_imp[nc_dta$treat==1], na.rm = T)

summary(nc_dta$vote_primary_imp[nc_dta$treat==2])
sd(nc_dta$vote_primary_imp[nc_dta$treat==2], na.rm = T)

summary(nc_dta$vote_primary_imp[nc_dta$treat==3])
sd(nc_dta$vote_primary_imp[nc_dta$treat==3], na.rm = T)

summary(nc_dta$vote_primary_imp[nc_dta$treat==4])
sd(nc_dta$vote_primary_imp[nc_dta$treat==4], na.rm = T)

summary(nc_dta$vote_primary_imp[nc_dta$treat==5])
sd(nc_dta$vote_primary_imp[nc_dta$treat==5], na.rm = T)


# Party ID
crosstab(nc_dta$pid, nc_dta$treat)

summary(nc_dta$pid[nc_dta$treat==0])
sd(nc_dta$pid[nc_dta$treat==0], na.rm = T)

summary(nc_dta$pid[nc_dta$treat==1])
sd(nc_dta$pid[nc_dta$treat==1], na.rm = T)

summary(nc_dta$pid[nc_dta$treat==2])
sd(nc_dta$pid[nc_dta$treat==2], na.rm = T)

summary(nc_dta$pid[nc_dta$treat==3])
sd(nc_dta$pid[nc_dta$treat==3], na.rm = T)

summary(nc_dta$pid[nc_dta$treat==4])
sd(nc_dta$pid[nc_dta$treat==4], na.rm = T)

summary(nc_dta$pid[nc_dta$treat==5])
sd(nc_dta$pid[nc_dta$treat==5], na.rm = T)


# PID strength

crosstab(nc_dta$pid_strength, nc_dta$treat)

summary(nc_dta$pid_strength[nc_dta$treat==0])
sd(nc_dta$pid_strength[nc_dta$treat==0], na.rm = T)

summary(nc_dta$pid_strength[nc_dta$treat==1])
sd(nc_dta$pid_strength[nc_dta$treat==1], na.rm = T)

summary(nc_dta$pid_strength[nc_dta$treat==2])
sd(nc_dta$pid_strength[nc_dta$treat==2], na.rm = T)

summary(nc_dta$pid_strength[nc_dta$treat==3])
sd(nc_dta$pid_strength[nc_dta$treat==3], na.rm = T)

summary(nc_dta$pid_strength[nc_dta$treat==4])
sd(nc_dta$pid_strength[nc_dta$treat==4], na.rm = T)

summary(nc_dta$pid_strength[nc_dta$treat==5])
sd(nc_dta$pid_strength[nc_dta$treat==5], na.rm = T)


# Political interest
crosstab(nc_dta$pol_interest, nc_dta$treat)

summary(nc_dta$pol_interest[nc_dta$treat==0])
sd(nc_dta$pol_interest[nc_dta$treat==0], na.rm = T)

summary(nc_dta$pol_interest[nc_dta$treat==1])
sd(nc_dta$pol_interest[nc_dta$treat==1], na.rm = T)

summary(nc_dta$pol_interest[nc_dta$treat==2])
sd(nc_dta$pol_interest[nc_dta$treat==2], na.rm = T)

summary(nc_dta$pol_interest[nc_dta$treat==3])
sd(nc_dta$pol_interest[nc_dta$treat==3], na.rm = T)

summary(nc_dta$pol_interest[nc_dta$treat==4])
sd(nc_dta$pol_interest[nc_dta$treat==4], na.rm = T)

summary(nc_dta$pol_interest[nc_dta$treat==5])
sd(nc_dta$pol_interest[nc_dta$treat==5], na.rm = T)


# Talk politics
crosstab(nc_dta$talk_politics, nc_dta$treat)

summary(nc_dta$talk_politics[nc_dta$treat==0])
sd(nc_dta$talk_politics[nc_dta$treat==0], na.rm = T)

summary(nc_dta$talk_politics[nc_dta$treat==1])
sd(nc_dta$talk_politics[nc_dta$treat==1], na.rm = T)

summary(nc_dta$talk_politics[nc_dta$treat==2])
sd(nc_dta$talk_politics[nc_dta$treat==2], na.rm = T)

summary(nc_dta$talk_politics[nc_dta$treat==3])
sd(nc_dta$talk_politics[nc_dta$treat==3], na.rm = T)

summary(nc_dta$talk_politics[nc_dta$treat==4])
sd(nc_dta$talk_politics[nc_dta$treat==4], na.rm = T)

summary(nc_dta$talk_politics[nc_dta$treat==5])
sd(nc_dta$talk_politics[nc_dta$treat==5], na.rm = T)


# Share political views
crosstab(nc_dta$shareviews_politics, nc_dta$treat)

summary(nc_dta$shareviews_politics[nc_dta$treat==0])
sd(nc_dta$shareviews_politics[nc_dta$treat==0], na.rm = T)

summary(nc_dta$shareviews_politics[nc_dta$treat==1])
sd(nc_dta$shareviews_politics[nc_dta$treat==1], na.rm = T)

summary(nc_dta$shareviews_politics[nc_dta$treat==2])
sd(nc_dta$shareviews_politics[nc_dta$treat==2], na.rm = T)

summary(nc_dta$shareviews_politics[nc_dta$treat==3])
sd(nc_dta$shareviews_politics[nc_dta$treat==3], na.rm = T)

summary(nc_dta$shareviews_politics[nc_dta$treat==4])
sd(nc_dta$shareviews_politics[nc_dta$treat==4], na.rm = T)

summary(nc_dta$shareviews_politics[nc_dta$treat==5])
sd(nc_dta$shareviews_politics[nc_dta$treat==5], na.rm = T)


# Talk to like minded people
crosstab(nc_dta$likeminded_politics, nc_dta$treat)

summary(nc_dta$likeminded_politics[nc_dta$treat==0])
sd(nc_dta$likeminded_politics[nc_dta$treat==0], na.rm = T)

summary(nc_dta$likeminded_politics[nc_dta$treat==1])
sd(nc_dta$likeminded_politics[nc_dta$treat==1], na.rm = T)

summary(nc_dta$likeminded_politics[nc_dta$treat==2])
sd(nc_dta$likeminded_politics[nc_dta$treat==2], na.rm = T)

summary(nc_dta$likeminded_politics[nc_dta$treat==3])
sd(nc_dta$likeminded_politics[nc_dta$treat==3], na.rm = T)

summary(nc_dta$likeminded_politics[nc_dta$treat==4])
sd(nc_dta$likeminded_politics[nc_dta$treat==4], na.rm = T)

summary(nc_dta$likeminded_politics[nc_dta$treat==5])
sd(nc_dta$likeminded_politics[nc_dta$treat==5], na.rm = T)


# Ideology 

crosstab(nc_dta$ideo7, nc_dta$treat)

summary(nc_dta$ideo7[nc_dta$treat==0])
sd(nc_dta$ideo7[nc_dta$treat==0], na.rm = T)

summary(nc_dta$ideo7[nc_dta$treat==1])
sd(nc_dta$ideo7[nc_dta$treat==1], na.rm = T)

summary(nc_dta$ideo7[nc_dta$treat==2])
sd(nc_dta$ideo7[nc_dta$treat==2], na.rm = T)

summary(nc_dta$ideo7[nc_dta$treat==3])
sd(nc_dta$ideo7[nc_dta$treat==3], na.rm = T)

summary(nc_dta$ideo7[nc_dta$treat==4])
sd(nc_dta$ideo7[nc_dta$treat==4], na.rm = T)

summary(nc_dta$ideo7[nc_dta$treat==5])
sd(nc_dta$ideo7[nc_dta$treat==5], na.rm = T)


# Party registration
crosstab(nc_dta$party_reg, nc_dta$treat)

summary(nc_dta$party_reg[nc_dta$treat==0])
sd(nc_dta$party_reg[nc_dta$treat==0], na.rm = T)

summary(nc_dta$party_reg[nc_dta$treat==1])
sd(nc_dta$party_reg[nc_dta$treat==1], na.rm = T)

summary(nc_dta$party_reg[nc_dta$treat==2])
sd(nc_dta$party_reg[nc_dta$treat==2], na.rm = T)

summary(nc_dta$party_reg[nc_dta$treat==3])
sd(nc_dta$party_reg[nc_dta$treat==3], na.rm = T)

summary(nc_dta$party_reg[nc_dta$treat==4])
sd(nc_dta$party_reg[nc_dta$treat==4], na.rm = T)

summary(nc_dta$party_reg[nc_dta$treat==5])
sd(nc_dta$party_reg[nc_dta$treat==5], na.rm = T)


# Move to North Carolina
crosstab(nc_dta$moveto_nc, nc_dta$treat)

summary(nc_dta$moveto_nc[nc_dta$treat==0])
sd(nc_dta$moveto_nc[nc_dta$treat==0], na.rm = T)

summary(nc_dta$moveto_nc[nc_dta$treat==1])
sd(nc_dta$moveto_nc[nc_dta$treat==1], na.rm = T)

summary(nc_dta$moveto_nc[nc_dta$treat==2])
sd(nc_dta$moveto_nc[nc_dta$treat==2], na.rm = T)

summary(nc_dta$moveto_nc[nc_dta$treat==3])
sd(nc_dta$moveto_nc[nc_dta$treat==3], na.rm = T)

summary(nc_dta$moveto_nc[nc_dta$treat==4])
sd(nc_dta$moveto_nc[nc_dta$treat==4], na.rm = T)

summary(nc_dta$moveto_nc[nc_dta$treat==5])
sd(nc_dta$moveto_nc[nc_dta$treat==5], na.rm = T)



# Age
crosstab(nc_dta$age, nc_dta$treat)

summary(nc_dta$age[nc_dta$treat==0])
sd(nc_dta$age[nc_dta$treat==0], na.rm = T)

summary(nc_dta$age[nc_dta$treat==1])
sd(nc_dta$age[nc_dta$treat==1], na.rm = T)

summary(nc_dta$age[nc_dta$treat==2])
sd(nc_dta$age[nc_dta$treat==2], na.rm = T)

summary(nc_dta$age[nc_dta$treat==3])
sd(nc_dta$age[nc_dta$treat==3], na.rm = T)

summary(nc_dta$age[nc_dta$treat==4])
sd(nc_dta$age[nc_dta$treat==4], na.rm = T)

summary(nc_dta$age[nc_dta$treat==5])
sd(nc_dta$age[nc_dta$treat==5], na.rm = T)


# Female
crosstab(nc_dta$female, nc_dta$treat)

summary(nc_dta$female[nc_dta$treat==0])
sd(nc_dta$female[nc_dta$treat==0], na.rm = T)

summary(nc_dta$female[nc_dta$treat==1])
sd(nc_dta$female[nc_dta$treat==1], na.rm = T)

summary(nc_dta$female[nc_dta$treat==2])
sd(nc_dta$female[nc_dta$treat==2], na.rm = T)

summary(nc_dta$female[nc_dta$treat==3])
sd(nc_dta$female[nc_dta$treat==3], na.rm = T)

summary(nc_dta$female[nc_dta$treat==4])
sd(nc_dta$female[nc_dta$treat==4], na.rm = T)

summary(nc_dta$female[nc_dta$treat==5])
sd(nc_dta$female[nc_dta$treat==5], na.rm = T)


# Race

table(nc_dta$whitenh, nc_dta$treat)

summary(nc_dta$whitenh[nc_dta$treat==0])
sd(nc_dta$whitenh[nc_dta$treat==0], na.rm = T)

summary(nc_dta$whitenh[nc_dta$treat==1])
sd(nc_dta$whitenh[nc_dta$treat==1], na.rm = T)

summary(nc_dta$whitenh[nc_dta$treat==2])
sd(nc_dta$whitenh[nc_dta$treat==2], na.rm = T)

summary(nc_dta$whitenh[nc_dta$treat==3])
sd(nc_dta$whitenh[nc_dta$treat==3], na.rm = T)

summary(nc_dta$whitenh[nc_dta$treat==4])
sd(nc_dta$whitenh[nc_dta$treat==4], na.rm = T)

summary(nc_dta$whitenh[nc_dta$treat==5])
sd(nc_dta$whitenh[nc_dta$treat==5], na.rm = T)


# Hispanic origin
crosstab(nc_dta$hispanic_origin, nc_dta$treat)

summary(nc_dta$hispanic_origin[nc_dta$treat==0])
sd(nc_dta$hispanic_origin[nc_dta$treat==0], na.rm = T)

summary(nc_dta$hispanic_origin[nc_dta$treat==1])
sd(nc_dta$hispanic_origin[nc_dta$treat==1], na.rm = T)

summary(nc_dta$hispanic_origin[nc_dta$treat==2])
sd(nc_dta$hispanic_origin[nc_dta$treat==2], na.rm = T)

summary(nc_dta$hispanic_origin[nc_dta$treat==3])
sd(nc_dta$hispanic_origin[nc_dta$treat==3], na.rm = T)

summary(nc_dta$hispanic_origin[nc_dta$treat==4])
sd(nc_dta$hispanic_origin[nc_dta$treat==4], na.rm = T)

summary(nc_dta$hispanic_origin[nc_dta$treat==5])
sd(nc_dta$hispanic_origin[nc_dta$treat==5], na.rm = T)


# Education

crosstab(nc_dta$education, nc_dta$treat)

summary(nc_dta$education[nc_dta$treat==0])
sd(nc_dta$education[nc_dta$treat==0], na.rm = T)

summary(nc_dta$education[nc_dta$treat==1])
sd(nc_dta$education[nc_dta$treat==1], na.rm = T)

summary(nc_dta$education[nc_dta$treat==2])
sd(nc_dta$education[nc_dta$treat==2], na.rm = T)

summary(nc_dta$education[nc_dta$treat==3])
sd(nc_dta$education[nc_dta$treat==3], na.rm = T)

summary(nc_dta$education[nc_dta$treat==4])
sd(nc_dta$education[nc_dta$treat==4], na.rm = T)

summary(nc_dta$education[nc_dta$treat==5])
sd(nc_dta$education[nc_dta$treat==5], na.rm = T)


##=========================================================================##
## Appendix C Table C1: Linear regression models for attentive respondents ##
##=========================================================================##

fl_dta <- data.table(fl_dta)
nc_dta <- data.table(nc_dta)

##---------##
## Florida ##
##---------##

# Full model for all
mf_all <- lm(dv_reg_all ~ factor(treatment) + vote_primary_imp + 
               pid_strength_cat4 + ideo_strength + age + female + whitenh + education +
               likeminded_politics + pol_interest + pol_engagement5 + 
               moveto_fl, data = fl_dta[fl_dta$attention_check==1 & fl_dta$resident==1])
summary(mf_all)

# Full model for independents
mf_ind <- lm(dv_reg_ind ~ factor(treatment) + vote_primary_imp +
               ideo_strength + age + female + whitenh + education + likeminded_politics + 
               pol_interest + pol_engagement5 + moveto_fl + pid_lean, 
             data = fl_dta[fl_dta$attention_check==1 & fl_dta$resident==1 & 
                             (fl_dta$pid_lean==1 | fl_dta$pid_lean==0)])
summary(mf_ind)

# Full model for partisans
mf_partisan <- lm(dv_reg_partisan ~ factor(treatment) + vote_primary_imp +
                    ideo_strength + age + female + whitenh + education + likeminded_politics + 
                    pol_interest + pol_engagement5 + moveto_fl + pid_strong, 
                  data = fl_dta[fl_dta$attention_check==1 & fl_dta$resident==1 & 
                                  (fl_dta$pid_strong==1 | fl_dta$pid_strong==0)])
summary(mf_partisan)

##----------------##
## North Carolina ##
##----------------##

# Full model for all
mf_all_nc <- lm(dv_reg_all ~ factor(treatment) + vote_primary_imp + 
                  pid_strength_cat4 + ideo_strength + age + female + whitenh + education +
                  likeminded_politics + pol_interest + pol_engagement5 + 
                  moveto_nc, data = nc_dta[nc_dta$attention_check==1 & nc_dta$resident==1])
summary(mf_all_nc)

# Full model for independents
mf_ind_nc <- lm(dv_reg_ind ~ factor(treatment) + vote_primary_imp +
                  ideo_strength + age + female + whitenh + education + likeminded_politics + 
                  pol_interest + pol_engagement5 + moveto_nc + pid_lean, 
                data = nc_dta[nc_dta$attention_check==1 & nc_dta$resident==1 & 
                                (nc_dta$pid_lean==1 | nc_dta$pid_lean==0)])
summary(mf_ind_nc)

# Full model for partisans
mf_partisan_nc <- lm(dv_reg_partisan ~ factor(treatment) + vote_primary_imp +
                       ideo_strength + age + female + whitenh + education + likeminded_politics + 
                       pol_interest + pol_engagement5 + moveto_nc + pid_strong, 
                     data = nc_dta[nc_dta$attention_check==1 & nc_dta$resident==1 & 
                                     (nc_dta$pid_strong==1 | nc_dta$pid_strong==0)])
summary(mf_partisan_nc)

#================================#
# Model Output Appendix Table C1 #
#================================#
texreg(list(mf_all, mf_all_nc, mf_ind, mf_ind_nc, mf_partisan, mf_partisan_nc),
       caption="Linear regression full models for suggested party registration",
       digits = 3,
       dcolumn=FALSE,
       model.names=c("mf_all", "mf_all_nc", "mf_ind", "mf_ind_nc", "mf_partisan", "mf_partisan_nc"),
       override.se=list(summary(mf_all)$coef[,2],
                        summary(mf_all_nc)$coef[,2],
                        summary(mf_ind)$coef[,2],
                        summary(mf_ind_nc)$coef[,2],
                        summary(mf_partisan)$coef[,2],
                        summary(mf_partisan_nc)$coef[,2],
                        override.pval=list(summary(mf_all)$coef[,4],
                                           summary(mf_all_nc)$coef[,4],
                                           summary(mf_ind)$coef[,4],
                                           summary(mf_ind_nc)$coef[,4],
                                           summary(mf_partisan)$coef[,4],
                                           summary(mf_partisan_nc)$coef[,4])))



##=======================================================================##
## Appendix C Table C2: Linear regression models for manipulation check  ##
##=======================================================================##

##---------##
## Florida ##
##---------##

fl_dta <- data.table(fl_dta)

# Full model for all
mf_all <- lm(dv_reg_all ~ factor(treatment) + vote_primary_imp + 
               pid_strength_cat4 + ideo_strength + age + female + whitenh + education +
               likeminded_politics + pol_interest + pol_engagement5 + 
               moveto_fl, data = fl_dta[fl_dta$manipulation_check==1 & fl_dta$resident==1])
summary(mf_all)

# Full model for independents
mf_ind <- lm(dv_reg_ind ~ factor(treatment) + vote_primary_imp +
               ideo_strength + age + female + whitenh + education + likeminded_politics + 
               pol_interest + pol_engagement5 + moveto_fl + pid_lean, 
             data = fl_dta[fl_dta$manipulation_check==1 & fl_dta$resident==1 & 
                             (fl_dta$pid_lean==1 | fl_dta$pid_lean==0)])
summary(mf_ind)

# Full model for partisans
mf_partisan <- lm(dv_reg_partisan ~ factor(treatment) + vote_primary_imp +
                    ideo_strength + age + female + whitenh + education + likeminded_politics + 
                    pol_interest + pol_engagement5 + moveto_fl + pid_strong, 
                  data = fl_dta[fl_dta$manipulation_check==1 & fl_dta$resident==1 & 
                                  (fl_dta$pid_strong==1 | fl_dta$pid_strong==0)])
summary(mf_partisan)


##----------------##
## North Carolina ##
##----------------##

nc_dta <- data.table(nc_dta)

# Full model for all
mf_all_nc <- lm(dv_reg_all ~ factor(treatment) + vote_primary_imp + 
                  pid_strength_cat4 + ideo_strength + age + female + whitenh + education +
                  likeminded_politics + pol_interest + pol_engagement5 + 
                  moveto_nc, data = nc_dta[nc_dta$manipulation_check==1 & nc_dta$resident==1])
summary(mf_all_nc)

# Full model for independents
mf_ind_nc <- lm(dv_reg_ind ~ factor(treatment) + vote_primary_imp +
                  ideo_strength + age + female + whitenh + education + likeminded_politics + 
                  pol_interest + pol_engagement5 + moveto_nc + pid_lean, 
                data = nc_dta[nc_dta$manipulation_check==1 & nc_dta$resident==1 & 
                                (nc_dta$pid_lean==1 | nc_dta$pid_lean==0)])
summary(mf_ind_nc)

# Full model for partisans
mf_partisan_nc <- lm(dv_reg_partisan ~ factor(treatment) + vote_primary_imp +
                       ideo_strength + age + female + whitenh + education + likeminded_politics + 
                       pol_interest + pol_engagement5 + moveto_nc + pid_strong, 
                     data = nc_dta[nc_dta$manipulation_check==1 & nc_dta$resident==1 & 
                                     (nc_dta$pid_strong==1 | nc_dta$pid_strong==0)])
summary(mf_partisan_nc)


#================================#
# Model Output Appendix Table C2 #
#================================#

texreg(list(mf_all, mf_all_nc, mf_ind, mf_ind_nc, mf_partisan, mf_partisan_nc),
       caption="Linear regression full models for suggested party registration",
       digits = 3,
       dcolumn=FALSE,
       model.names=c("mf_all", "mf_all_nc", "mf_ind", "mf_ind_nc", "mf_partisan", "mf_partisan_nc"),
       override.se=list(summary(mf_all)$coef[,2],
                        summary(mf_all_nc)$coef[,2],
                        summary(mf_ind)$coef[,2],
                        summary(mf_ind_nc)$coef[,2],
                        summary(mf_partisan)$coef[,2],
                        summary(mf_partisan_nc)$coef[,2],
                        override.pval=list(summary(mf_all)$coef[,4],
                                           summary(mf_all_nc)$coef[,4],
                                           summary(mf_ind)$coef[,4],
                                           summary(mf_ind_nc)$coef[,4],
                                           summary(mf_partisan)$coef[,4],
                                           summary(mf_partisan_nc)$coef[,4])))


##===================================================================================##
## Appendix D Table D1: Linear regression models including non attentive respondents ##
##===================================================================================##

##---------##
## Florida ## 
##---------##

# treatment for all
m1_alln <- lm(dv_reg_all ~ factor(treatment), data = fl_dta[fl_dta$resident==1])
summary(m1_alln)

# treatment for independents
m1_indn <- lm(dv_reg_ind ~ factor(treatment), data = fl_dta[fl_dta$resident==1 & 
                                                              (fl_dta$pid_lean==1 | fl_dta$pid_lean==0)])
summary(m1_indn)

# treatment for partisans
m1_partisann <- lm(dv_reg_partisan ~ factor(treatment), data = fl_dta[fl_dta$resident==1 & 
                                                                        (fl_dta$pid_strong==1 | fl_dta$pid_strong==0)])
summary(m1_partisann)


##----------------##
## North Carolina ## 
##----------------##

# treatment for all
m1_alln_nc <- lm(dv_reg_all ~ factor(treatment), data = nc_dta[nc_dta$resident==1])
summary(m1_alln_nc)


# treatment for independents
m1_indn_nc <- lm(dv_reg_ind ~ factor(treatment), data = nc_dta[nc_dta$resident==1 & 
                                                                 (nc_dta$pid_lean==1 | nc_dta$pid_lean==0)])
summary(m1_indn_nc)


# treatment for partisans
m1_partisann_nc <- lm(dv_reg_partisan ~ factor(treatment), data = nc_dta[nc_dta$resident==1 & 
                                                                           (nc_dta$pid_strong==1 | nc_dta$pid_strong==0)])
summary(m1_partisann_nc)

#=======================#
# Model Output Table D1 #
#=======================#

texreg(list(m1_alln, m1_alln_nc, m1_indn, m1_indn_nc, m1_partisann, m1_partisann_nc),
       caption="Linear regression modelsfor suggestedpartyregistration",
       digits = 3,
       dcolumn=FALSE,
       model.names=c("m1_alln", "m1_alln_nc", "m1_indn", "m1_indn_nc", "m1_partisann", "m1_partisann_nc"),
       override.se=list(summary(m1_alln)$coef[,2],
                        summary(m1_alln_nc)$coef[,2],
                        summary(m1_indn)$coef[,2],
                        summary(m1_indn_nc)$coef[,2],
                        summary(m1_partisann)$coef[,2],
                        summary(m1_partisann_nc)$coef[,2],
                        override.pval=list(summary(m1_alln)$coef[,4],
                                           summary(m1_alln_nc)$coef[,4],
                                           summary(m1_indn)$coef[,4],
                                           summary(m1_indn_nc)$coef[,4],
                                           summary(m1_partisann)$coef[,4],
                                           summary(m1_partisann_nc)$coef[,4])))


##===========================================================================##
## Appendix E Table E1: Logistic regression models for attentive respondents ##
##===========================================================================##

##---------##
## Florida ##
##---------##

# treatment for all
m1_all_l <- glm(dv_reg_all ~ factor(treatment), data = fl_dta[fl_dta$attention_check==1 & fl_dta$resident==1], 
                family = binomial)
summary(m1_all_l)

# treatment for independents
m1_ind_l <- glm(dv_reg_ind ~ factor(treatment), data = fl_dta[fl_dta$attention_check==1 & fl_dta$resident==1 & 
                                                                (fl_dta$pid_lean==1 | fl_dta$pid_lean==0)], family = binomial)
summary(m1_ind_l)

# treatment for partisans
m1_partisan_l <- glm(dv_reg_partisan ~ factor(treatment), data = fl_dta[fl_dta$attention_check==1 & fl_dta$resident==1 & 
                                                                          (fl_dta$pid_strong==1 | fl_dta$pid_strong==0)], family = binomial)
summary(m1_partisan_l)


##----------------##
## North Carolina ##
##----------------##

# treatment for all
m1_all_l_nc <- glm(dv_reg_all ~ factor(treatment), data = nc_dta[nc_dta$attention_check==1 & nc_dta$resident==1], 
                   family = binomial)
summary(m1_all_l_nc)


# treatment for independents
m1_ind_l_nc <- glm(dv_reg_ind ~ factor(treatment), data = nc_dta[nc_dta$attention_check==1 & nc_dta$resident==1 & 
                                                                   (nc_dta$pid_lean==1 | nc_dta$pid_lean==0)], family = binomial)
summary(m1_ind_l_nc)


# treatment for partisans
m1_partisan_l_nc <- glm(dv_reg_partisan ~ factor(treatment), data = nc_dta[nc_dta$attention_check==1 & nc_dta$resident==1 & 
                                                                             (nc_dta$pid_strong==1 | nc_dta$pid_strong==0)], family = binomial)
summary(m1_partisan_l_nc)


#=======================#
# Model Output Table E1 #
#=======================#

texreg(list(m1_all_l, m1_all_l_nc, m1_ind_l, m1_ind_l_nc, m1_partisan_l, m1_partisan_l_nc),
       caption="Logistic regression models for attentive respondents",
       digits = 3,
       dcolumn=FALSE,
       model.names=c("m1_all_l", "m1_all_l_nc", "m1_ind_l", "m1_ind_l_nc", "m1_partisan_l", "m1_partisan_l_nc"),
       override.se=list(summary(m1_all_l)$coef[,2],
                        summary(m1_all_l_nc)$coef[,2],
                        summary(m1_ind_l)$coef[,2],
                        summary(m1_ind_l_nc)$coef[,2],
                        summary(m1_partisan_l)$coef[,2],
                        summary(m1_partisan_l_nc)$coef[,2],
                        override.pval=list(summary(m1_all_l)$coef[,4],
                                           summary(m1_all_l_nc)$coef[,4],
                                           summary(m1_ind_l)$coef[,4],
                                           summary(m1_ind_l_nc)$coef[,4],
                                           summary(m1_partisan_l)$coef[,4],
                                           summary(m1_partisan_l_nc)$coef[,4])))



##======================================##
## Appendix F Figure F1: ANES Line plot ##
##======================================##

data_anes2 <- read_excel("/Users/Enrijeta/Dropbox/Hood et al. Registered Indies/figures/anes_plot2.xlsx")

data3 <- data_anes2 %>% 
  pivot_longer(!Year, names_to = "Group") %>% 
  mutate(Group = fct_relevel(Group, c("Ind_Lean", "Weak_Strong"))) %>%
  arrange(Group) %>% 
  mutate(Group = recode(Group, "Ind_Lean" = "Independents", "Weak_Strong" = "Partisans")) %>% 
  filter(Group %in% c("Independents", "Partisans"))

plot3 <- 
  ggplot(data = data3, aes(x = Year, y = value, colour = Group)) +
  geom_line(aes(linetype = Group)) +
  xlab("") +
  ylab("Percent(%)") +
  scale_linetype_manual(values = c("dashed", "solid")) + 
  scale_color_manual(values=c("black", "black")) +
  scale_y_continuous(breaks = seq(0, 100, by = 10), limits = c(0, 100)) +
  scale_x_continuous("", labels = as.character(data3$Year), breaks = data3$Year) +
  theme_bw() +  theme(panel.background = element_rect(fill = "white"), text = element_text(size = 12),
                      legend.position = "bottom", legend.title = element_blank()) 


# save graph in overleaf
ggsave(filename = "/Users/Enrijeta/Dropbox/Apps/Overleaf/Independents_treatment/plots/anes_lineplot2.pdf", width = 8, height = 6)


##======================================##
## Appendix F Figure F2: ANES Line plot ##
##======================================##

data_anes <- read_excel("/Users/Enrijeta/Dropbox/Hood et al. Registered Indies/figures/anes_plot.xlsx")

data2 <- data_anes %>% 
  pivot_longer(!Year, names_to = "Group") %>% 
  mutate(Group = fct_relevel(Group, c("Ind_per", "Lean_per", "Weak_per", 
                                      "Strong_per"))) %>%
  arrange(Group) %>% 
  mutate(Group = recode(Group, "Ind_per" = "Independent", "Lean_per" = "Leaning Independent", 
                        "Weak_per" = "Weak Partisan", "Strong_per" = "Strong Partisan")) %>% 
  filter(Group %in% c('Independent', "Leaning Independent", "Weak Partisan", "Strong Partisan"))

plot2 <- 
  ggplot(data = data2, aes(x = Year, y = value, colour = Group)) +
  geom_line(aes(linetype = Group)) +
  xlab("") +
  ylab("Register as NPA / Unaffiliated") +
  scale_linetype_manual(values = c("dashed", "solid", "dotted", "solid")) + 
  scale_color_manual(values=c("black","gray","black","black")) +
  scale_y_continuous(breaks = seq(0, 50, by = 5), limits = c(0, 50)) +
  scale_x_continuous("", labels = as.character(data2$Year), breaks = data2$Year) +
  theme_bw() +  theme(panel.background = element_rect(fill = "white"), text = element_text(size = 12),
                      legend.title = element_blank(), legend.position = "bottom") 


# save graph in overleaf
ggsave(filename = "/Users/Enrijeta/Dropbox/Apps/Overleaf/Independents_treatment/appendix/anes_lineplot1.pdf", width = 8, height = 6)



##=====================================##
## Appendix F Figure F3: CES Line plot ##
##=====================================##

data_ces <- read_excel("/Users/Enrijeta/Dropbox/Hood et al. Registered Indies/figures/ces_plot.xlsx")

data2_ces <- data_ces %>% 
  pivot_longer(!Year, names_to = "Group") %>% 
  mutate(Group = fct_relevel(Group, c("Ind_per", "Lean_per", "Weak_per", 
                                      "Strong_per"))) %>%
  arrange(Group) %>% 
  mutate(Group = recode(Group, "Ind_per" = "Independent", "Lean_per" = "Leaning Independent", 
                        "Weak_per" = "Weak Partisan", "Strong_per" = "Strong Partisan")) %>% 
  filter(Group %in% c('Independent', "Leaning Independent", "Weak Partisan", "Strong Partisan"))

plot_ces <- 
  ggplot(data = data2_ces, aes(x = Year, y = value, colour = Group)) +
  geom_line(aes(linetype = Group)) +
  xlab("") +
  ylab("Register as NPA / Unaffiliated") +
  scale_linetype_manual(values = c("dashed", "solid", "dotted", "solid")) + 
  scale_color_manual(values=c("black","gray","black","black")) +
  scale_y_continuous(breaks = seq(0, 50, by = 5), limits = c(0, 50)) +
  scale_x_continuous("", labels = as.character(data2_ces$Year), breaks = data2_ces$Year) +
  theme_bw() +  theme(panel.background = element_rect(fill = "white"), text = element_text(size = 12),
                      legend.title = element_blank(), legend.position = "bottom") 


# save graph in overleaf
ggsave(filename = "/Users/Enrijeta/Dropbox/Apps/Overleaf/Independents_treatment/appendix/ces_lineplot.pdf", width = 8, height = 6)




